const fp = require('lodash/fp');
const {Maybe, Container} = require('./support.js');

const maybe = Maybe.of([5, 6, 1]);

// 是每个值增加
const ex1 = (n) => maybe.map((arr) => fp.map((v) => fp.add(v, n), arr));
console.log(ex1(1));

const xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do']);

// 取第一个元素
const ex2 = (fn) => xs.map(fn)._value;

console.log(ex2(fp.first));

const safeProp = fp.curry(function (x, o) {
	return Maybe.of(o[x]);
});

const user = {id: 2, name: 'Albert'};

// 取首字母
const ex3 = () => safeProp('name', user).map(fp.first)._value;
console.log(ex3());

// 取整
const ex4 = (n) => Maybe.of(n).map(parseInt)._value;
console.log(ex4('1a'));
